let express = require('express');
let query = require('./Database');
let router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('smRecord', {});
});
router.post('/AddCart',async (req, res) => {
    let record = req.body;
    let rows = await query('insert into goods(cartname,cartimgsrc,cartversion,cartcolor,cartprice,cartcount,userid,shopid,state,goodstime) values("'+ record.cartname +'","'+ record.cartimgsrc +'","'+ record.cartversion +'","'+ record.cartcolor +'","'+ record.cartprice +'","'+ record.cartcount +'","'+ record.userid +'","'+ record.shopid +'","'+ record.state +'","'+ record.goodstime +'")');
    // let ProductId = await query('select id from goods where userid=1 order by id desc limit 1');
    let data = {
        code:100,
        // productid: ProductId[0].id
    };
    res.send(data);
});
router.post('/theproduct',async (req, res) => {
    let list = req.body;
    let rows = await query("select * from product join shop where product.shopid = shop.id and product.id = " + list.id);
    console.log(rows);
    // let ProductId = await query('select id from goods where userid=1 order by id desc limit 1');
    let data = [{code:100,},rows];
    res.send(data);
});
router.post('/collect',async (req, res) => {
    let list = req.body;
    console.log(list);
    await query("insert into goods(cartname,cartimgsrc,cartprice,userid,shopid,state,goodstime,productid) values('"+list.cartname+"','"+list.cartimgsrc+"',"+list.cartprice+","+list.userid+","+list.shopid+",13,"+list.goodstime+","+list.product+")");
    // let ProductId = await query('select id from goods where userid=1 order by id desc limit 1');
    let data = {code:100,};
    res.send(data);
});
module.exports = router;